import { createRouter, createWebHashHistory } from 'vue-router'

import Home from 'layout/Home.vue'

export const constantRoutes = [
  {
    path: '/',
    redirect: '/oneModular',
    hidden: true
  },
  {
    path: '/login',
    component: () => import('page/Login.vue'),
    meta: {
      title: '结算模板-登录'
    },
    hidden: true
  },
  {
    path: '/dingding',
    component: () => import('page/Ding.vue'),
    meta: {
      title: '结算模板-钉钉绑定'
    },
    hidden: true
  },
  {
    path: '/404',
    component: () => import('page/404.vue'),
    meta: {
      title: '404'
    },
    hidden: true
  },
  {
    path: '/403',
    component: () => import('page/403.vue'),
    meta: {
      title: '403'
    },
    hidden: true
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('page/404.vue'),
    meta: {
      title: '404'
    },
    hidden: true
  }
]

export const asyncRoutes = [
  {
    path: '/oneModular',
    component: Home,
    redirect: '/oneModular',
    name: 'oneModular',
    meta: {
      sort: 1,
      title: '表单衍生组件',
      code: '01000000',
      icon: 'AccountBookFilled',
      key: '1'
    },
    children: [
      {
        path: '/oneModular/paymentManage',
        component: () => import('page/oneModular/index'),
        name: 'paymentManage',
        redirect: '/oneModular/paymentManage/index',
        meta: {
          title: 'baseSearch示例',
          code: '01010000',
          key: '1-1'
        },
        children: [
          {
            path: '/oneModular/paymentManage/index',
            component: () => import('page/oneModular/paymentManage'),
            name: 'index',
            meta: {
              keepAlive: true,
              breadcrumb: false,
              title: 'baseSearch示例',
              code: '01010000',
              key: '1-1'
            }
          }
        ]
      },
      {
        path: '/oneModular/Upload/index',
        component: () => import('page/oneModular/Upload'),
        name: 'Upload',
        meta: {
          title: 'Upload示例',
          code: '01020000',
          key: '1-2'
        }
      },
      {
        path: '/oneModular/viewEdit/index',
        component: () => import('page/oneModular/viewEdit'),
        name: 'viewEdit',
        meta: {
          title: 'viewEdit示例',
          code: '01030000',
          key: '1-3'
        }
      },
    ]
  },
  {
    path: '/twoModular',
    component: Home,
    redirect: '/twoModular',
    name: 'twoModular',
    meta: {
      sort: 2,
      title: '第二模块',
      code: '03000000',
      icon: 'AppstoreFilled',
      key: '3'
    },
    children: [
      {
        path: '/twoModular/Table',
        component: () => import('page/twoModular/index'),
        name: 'Table',
        redirect: '/twoModular/Table/index',
        meta: {
          title: 'Table',
          code: '03010000',
          key: '3-1'
        },
        children: [
          {
            path: '/twoModular/Table/index',
            component: () => import('page/twoModular/Table'),
            name: 'oneManageIndex',
            meta: {
              keepAlive: true,
              breadcrumb: false,
              title: 'Table',
              code: '03010000',
              key: '3-1'
            }
          },
          {
            path: '/twoModular/Table/option',
            component: () => import('page/twoModular/Table/option.vue'),
            name: 'oneManageOption',
            hidden: true,
            meta: {
              keepAlive: false,
              title: '第一管理详情',
              code: '03010001',
              key: '3-1'
            }
          }
        ]
      },
      {
        path: '/twoModular/WangEditor',
        component: () => import('page/twoModular/index'),
        name: 'WangEditor',
        redirect: '/twoModular/WangEditor/index',
        meta: {
          title: 'WangEditor',
          code: '03020000',
          key: '3-2'
        },
        children: [
          {
            path: '/twoModular/WangEditor/index',
            component: () => import('page/twoModular/WangEditor'),
            name: 'twoManageIndex',
            meta: {
              keepAlive: true,
              breadcrumb: false,
              title: 'WangEditor',
              code: '03020000',
              key: '3-2'
            }
          },
          {
            path: '/twoModular/WangEditor/option',
            component: () => import('page/twoModular/WangEditor/option.vue'),
            name: 'twoManageOption',
            hidden: true,
            meta: {
              keepAlive: false,
              title: '第二管理详情',
              code: '03020001',
              key: '3-2'
            }
          }
        ]
      },
      {
        path: '/twoModular/turingTest',
        component: () => import('page/twoModular/index'),
        name: 'turingTest',
        redirect: '/twoModular/turingTest/index',
        meta: {
          title: '人机校验-图灵测试',
          code: '03010000',
          key: '3-3'
        },
        children: [
          {
            path: '/twoModular/turingTest/index',
            component: () => import('page/twoModular/turingTest'),
            name: 'turingTestIndex',
            meta: {
              keepAlive: true,
              breadcrumb: false,
              title: '人机校验-图灵测试',
              code: '03010000',
              key: '3-3'
            }
          }
        ]
      },
      {
        path: '/twoModular/fourManage/index',
        component: () => import('page/twoModular/fourManage'),
        name: 'fourManage',
        meta: {
          title: '手写签名',
          code: '03040000',
          key: '3-4'
        }
      }
    ]
  }
]

const _createRouter = () =>
  createRouter({
    history: createWebHashHistory(),
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = _createRouter()

export function resetRouter() {
  const newRouter = _createRouter()
  router.matcher = newRouter.matcher
}

export default router
